<template>
  <div class="active">
    <el-form :inline="true" :model="form" class="t-form gray">
      <el-form-item label="">
        <el-input v-model="form.keyword" placeholder="请输入活动名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search" class="search-btn">查询</el-button>
      </el-form-item>
      <el-form-item class="new-item">
        <el-button v-if="config.model_activity_add" type="primary" class="new-btn" @click="$router.push('/main/exam/active/add')">新建活动</el-button>
      </el-form-item>
    </el-form>
    <el-table class="line-table" empty-text="暂无活动，请先添加活动" :data="result.list" header-align="center">
      <el-table-column prop="name" label="活动名称" align="center"></el-table-column>
      <el-table-column prop="createUser" label="创建人" align="center"> </el-table-column>
      <el-table-column label="添加时间" align="center" width="180px">
        <template scope="scope">
          {{scope.row.createTime | formatDate('YYYY-MM-DD H:mm:ss')}}
        </template>
      </el-table-column>
      <el-table-column label="最后编辑时间" align="center" width="180px">
        <template scope="scope">
          {{scope.row.updateTime | formatDate('YYYY-MM-DD H:mm:ss')}}
        </template>
      </el-table-column>
      <el-table-column label="开放时间" align="center" width="180px">
        <template scope="scope">
          {{scope.row.openTime | formatDate('YYYY-MM-DD H:mm:ss')}}
        </template>
      </el-table-column>
      <el-table-column label="是否启用" align="center">
        <template scope="scope">
          {{scope.row.isUse===0?'否':'是'}}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="t-btn" width="300px">
        <template scope="scope">
          <span class="btn-edit" v-if="config.model_activity_update" @click="$router.push('/main/exam/active/'+scope.row.id)">
            编辑
          </span>
          <span class="btn-edit" v-if="config.model_list" @click="$router.push({path:'/main/exam/test-paper',query:{activeId:scope.row.id,activeName:scope.row.name}})">
            试卷模版列表
          </span>
        </template>
      </el-table-column>
    </el-table>
    <v-pagination ref="pagin" class="pag" :total="result.total|toNumber" @getListResult="getActiveList" :currentPage="form.pageIndex"></v-pagination>
  </div>
</template>
<script>
import VPagination from '../common/Pagination'
import { mapState, mapActions, mapGetters } from 'vuex'
import io from 'lib/io'
import storage from 'lib/storage'
export default {
  components: {
    VPagination
  },
  data() {
    return {
      form: {
        keyword: '',
        pageIndex: 1,
        pageSize: 10
      },
      userInfo: storage.getCurrentUserInfo(),
      result:{}
    }
  },
  computed: {
    // ...mapState(['exam']),
    // ...mapState({ result: state => state.exam.exam }),
    ...mapGetters(['config'])
  },
  created() {
    this.getActiveList()

  },
  methods: {
    // ...mapActions([ 'examModelList']),
    search() {
      this.$refs.pagin.changePage(1)
      this.form.pageIndex=1
      this.getActiveList()
    },
    async getActiveList(opt) {
      let {data}=await io.post6(io.examModelActivityList,{...this.form, ...opt})
      if(data.success){
        this.result=data.data
      }
      // this.examModelList({ ...this.form, ...opt, type: this.userInfo.isSystem ? 0 : 1 })
    },
  }
}
</script>
<style lang="stylus" scoped>
@import '~assets/stylus/mixin.styl'
.active
  padding-bottom 50px
.t-form
  table-form()
  margin-top 20px
  margin-bottom 30px

.btn-edit
  cursor  pointer
  color  #0084bb
  display  inline-block
  padding  9px 5px
  border-color #0084bb

</style>



      